/**
* 任务列表
 */
 <template>
  <div class="page-box h100 display-flex czbj dfddsrttre">
    <div class="mb10 display-flex" v-if="types == 0">
      <n-button @click="daorujjeer = true">导入</n-button>

      <div class="dfssrra ml10">
        <n-button @click="xiazai">下载模版</n-button>
      </div>
    </div>
    <div class="mb10 display-flex" v-if="types == 100">
      <n-button @click="daochukmse">导出</n-button>
    </div>
    <dxtable
      :dataJson="dataJson"
      :portUrl="portUrl"
      :qx="qx"
      :formJson="formJson"
      :headBtn="headBtn"
      :types="types"
      :extra="extra"
      ref="dxtableRef"
      :czFun="czFun"
      :isshowXz="isshowXz"
      :headerFrom="headerFrom"
      fixed="fixed"
      :hidebj="true"
    ></dxtable>

    <n-modal
      :mask-closable="false"
      v-model:show="showModal"
      preset="card"
      class="Stock-diagnosisdrrtt"
    >
      <template #header>
        <div>发起任务(请选择一个管理组)</div>
      </template>
      <div class="display-flex">
        <div class="mt5 dsfdsfsdr">管理组</div>
        <div class="flex-1 ml20">
          <n-select v-model:value="gval" :options="goptions" />
        </div>
      </div>
      <div class="display-flex mt20">
        <div class="mt5 dsfdsfsdr">备注</div>
        <div class="flex-1 ml20">
          <n-input
            v-model:value="remarksss"
            placeholder="请输入备注"
            size="medium"
          />
        </div>
      </div>
      <template #action>
        <div class="tr">
          <n-button @click="showModal = false"> 取消 </n-button>
          <n-button type="primary" @click="fdgdfgdra = true" class="ml20">
            新增管理组
          </n-button>
          <n-button
            type="primary"
            class="ml20"
            @click="getpitchOn(2, gval)"
            :disabled="!gval"
            :loading="gloading"
          >
            确认
          </n-button>
        </div>
      </template>
    </n-modal>

    <n-modal
      :mask-closable="false"
      v-model:show="showModaler"
      preset="card"
      class="Stock-diagnosisdrrtt"
    >
      <template #header>
        <div>分配任务(请选择一个勘察组！)</div>
      </template>
      <div class="display-flex">
        <div class="mt5 dsfdsfsdr">勘察组</div>
        <div class="flex-1 ml20">
          <n-select
            v-model:value="gvaler"
            :options="goptionser"
            @change="fjjnnerr"
          />
          <!-- <div class="mt20">
            <n-button type="primary" @click="fdgdfgdrb = true">
              新增勘察组
            </n-button>
          </div> -->
        </div>
      </div>
      <div class="display-flex mt20">
        <div class="mt5 dsfdsfsdr">组 员</div>
        <div class="flex-1 ml20">
          <n-select v-model:value="gvalercy" :options="jhnnerrr" />
        </div>
      </div>

      <template #action>
        <div class="tr">
          <n-button @click="showModaler = false"> 取消 </n-button>
          <n-button type="primary" @click="fdgdfgdrb = true" class="ml20">
            新增勘察组
          </n-button>
          <n-button
            type="primary"
            class="ml20"
            @click="getpitchOn(3, gvaler)"
            :disabled="!gvaler"
            :loading="gloading"
          >
            确认
          </n-button>
        </div>
      </template>
    </n-modal>

    <n-modal
      :mask-closable="false"
      v-model:show="showModalsan"
      preset="card"
      class="Stock-diagnosis"
    >
      <template #header>
        <div>审核</div>
      </template>
      <div class="knnjswerrw">
        <div v-for="(item, idx) in jnbnse" :key="idx" class="kknjseer">
          <p class="z3 fz16">任务id:{{ item.id }}</p>
          <div v-if="item.state == 15">
            取消原因：{{ item.reasonCancellation.yx }}
            <div>取消时间：{{ item.reasonCancellation.dq }}</div>
          </div>
          <div v-if="item.state == 8">
            <p>修改后的数量为</p>
            <div>
              <p>
                宣教一体机+便民充电宝个数:{{
                  item.modification.ConvenientChargingTreasure
                }}
              </p>
              <p>
                宣教一体机（壁挂式）个数:{{ item.modification.wallMounted }}
              </p>
              <p>
                AED智能售卖机（友宝）个数:{{
                  item.modification.FriendsTreasure
                }}
              </p>
              <p>AED智能取餐柜（饿了么）个数:{{ item.modification.EleMe }}</p>
            </div>
          </div>
        </div>
      </div>
      <div class="display-flex pt20">
        <div class="">是否同意通过任务</div>
        <div class="flex-1 ml20">
          <n-radio
            name="audit-radio"
            @change="jnnjeea"
            value="1"
            :checked="checkedValue === '1'"
          >
            同意
          </n-radio>
          <n-radio
            name="audit-radio"
            class="ml20"
            @change="jnnjeea"
            value="2"
            :checked="checkedValue === '2'"
          >
            拒绝
          </n-radio>
        </div>
      </div>
      <template #action>
        <div class="tr">
          <n-button @click="showModalsan = false"> 取消 </n-button>
          <n-button
            type="primary"
            class="ml20"
            @click="auditFun"
            :loading="gloading"
          >
            确认
          </n-button>
        </div>
      </template>
    </n-modal>

    <n-modal
      :mask-closable="false"
      v-model:show="showModalsi"
      preset="card"
      class="Stock-diagnosis"
    >
      <template #header>
        <div>任务详情</div>
      </template>
      <div class="display-flex">
        <div class="flex-1">
          <div class="display-flex dsfdsfrtewe">
            <div class="renwu-label">任务编号：</div>
            <div class="flex-1">{{ jhbeer.id }}</div>
          </div>
          <div class="display-flex dsfdsfrtewe">
            <div class="renwu-label">申报时间：</div>
            <div class="flex-1">{{ jhbeer.TheTime }}</div>
          </div>
          <div class="display-flex dsfdsfrtewe">
            <div class="renwu-label">申报方式：</div>
            <div class="flex-1">{{ getDeclareMeans(jhbeer.DeclareMeans) }}</div>
          </div>
          <div class="display-flex dsfdsfrtewe" v-if="jhbeer.DeclareMeans == 1">
            <div class="renwu-label">申报单位：</div>
            <div class="flex-1">{{ jhbeer.applicationUnit }}</div>
          </div>
          <div class="display-flex dsfdsfrtewe">
            <div class="renwu-label">场地类型：</div>
            <div class="flex-1">{{ getsiteSoil(jhbeer.typeOfSiteSoil) }}</div>
          </div>
          <div class="display-flex dsfdsfrtewe">
            <div class="renwu-label">场地名称：</div>
            <div class="flex-1">{{ jhbeer.SiteName }}</div>
          </div>
          <div class="display-flex dsfdsfrtewe">
            <div class="renwu-label">场地联系人：</div>
            <div class="flex-1">{{ jhbeer.VenueContactPerson }}</div>
          </div>
          <div class="display-flex dsfdsfrtewe">
            <div class="renwu-label">联系方式：</div>
            <div class="flex-1">{{ jhbeer.contactway }}</div>
          </div>
          <div class="display-flex dsfdsfrtewe">
            <div class="renwu-label">场地地址：</div>
            <div class="flex-1">
              {{
                getdizhi(jhbeer.district, jhbeer.street, jhbeer.detailedAddress)
              }}
            </div>
          </div>
          <div class="display-flex dsfdsfrtewe">
            <div class="renwu-label">状态：</div>
            <div class="flex-1">{{ getstatictype(jhbeer.state) }}</div>
          </div>
        </div>

        <div class="kjnseert" v-if="jhbeer.state != 15 && jhbeer.state != 16">
          <p class="z3 fz18">任务进度{{ jhbeer.state }}</p>
          <n-steps vertical :current="currentse" class="mt20">
            <template v-for="(item, idx) in listArr" :key="idx">
              <n-step :title="item.label">
                <span>{{ item.name }}</span>
                <div v-if="item.pdfName">
                  <span v-if="item.url">{{ item.pdfName }}:</span>
                  <div
                    v-if="item.pdfName == '协议'"
                    class="dfsdrtr ml20 sdfsdfdseer"
                  >
                    <n-upload
                      :action="prefixS + 'public/Upimg'"
                      :data="upload"
                      accept=".pdf"
                      @Finish="getImgs"
                      @before-upload="appload = true"
                    >
                      <n-button :loading="appload" type="primary" quaternary
                        >点击{{ !item.url ? "上传" : "修改" }}协议</n-button
                      >
                    </n-upload>
                  </div>
                  <a
                    class="ml20"
                    :href="item.url"
                    download
                    v-if="item.url"
                    target="_blank"
                    >查看</a
                  >
                </div>
                <div v-if="item.qxtime && currentse > 4" class="display-flex">
                  <span class="pt10">{{ item.qxtime }}:</span>
                  <div class="ml20" v-if="item.SigningTime">
                    <n-date-picker
                      v-model:value="timestamp"
                      :default-value="parseInt(item.SigningTime)"
                      type="date"
                      clearable
                    />
                    <div class="mt10">
                      <n-button type="primary" @click="quhgwe(item.taskId)">
                        {{ item.SigningTime ? "重签协议" : "确认已签协议" }}
                      </n-button>
                    </div>
                  </div>
                </div>
                <p>{{ item.time }}</p>
                <p
                  class="ls sz"
                  v-if="idx == 3 && item.time"
                  @click="showbiane(item.taskId, item.step)"
                >
                  查看勘察进度
                </p>
              </n-step>
            </template>
          </n-steps>
        </div>

        <div v-else class="kjnseert fz24 h100">
          取消原因： {{ getstatictypeer(jhbeer.reasonCancellation, "yx") }}
          <p>
            取消时间： {{ getstatictypeer(jhbeer.reasonCancellation, "dq") }}
          </p>
        </div>
      </div>
    </n-modal>

    <n-modal
      :mask-closable="false"
      v-model:show="daorujjeer"
      preset="card"
      class="Stock-diagnosisdrrtt"
    >
      <template #header>
        <div>批量导入</div>
      </template>
      <div>
        <n-alert title="导入注意" type="warning">
          场地地址的格式必须包含区和街道否则地址导入不成功
          <div class="red">示例:罗湖区黄贝街道xxxx</div>
        </n-alert>
        <div class="mt20 tr display-flex tr">
          <div>
            <n-button @click="daorujjeer = false"> 取消 </n-button>
          </div>
          <div class="ml20">
            <n-upload @before-upload="uploadxl" accept=".xls, .xlsx">
              <n-button type="primary" :loading="dftte">确认导入</n-button>
            </n-upload>
          </div>
        </div>
      </div>
    </n-modal>

    <n-modal
      :mask-closable="false"
      v-model:show="fdgdfgdra"
      preset="card"
      class="Stock-diagnosisdrrtt"
    >
      <template #header>
        <div>添加管理组</div>
      </template>
      <div>
        <n-input
          v-model:value="jheerr.name"
          type="text"
          placeholder="请输入组名称"
          clearable
        ></n-input>
        <n-input
          v-model:value="jheerr.remark"
          type="text"
          placeholder="请输入备注"
          clearable
          class="mt20"
        ></n-input>
      </div>

      <div class="mt20 tr display-flex tr">
        <div>
          <n-button @click="fdgdfgdra = false"> 取消 </n-button>
        </div>
        <div class="ml20">
          <n-button type="primary" @click="addZSde"> 确认 </n-button>
        </div>
      </div>
    </n-modal>

    <n-modal
      :mask-closable="false"
      v-model:show="fdgdfgdrb"
      preset="card"
      class="Stock-diagnosisdrrtt"
    >
      <template #header>
        <div>添加勘察组</div>
      </template>
      <div>
        <n-input
          v-model:value="jheerb.name"
          type="text"
          placeholder="请输入组名称"
          clearable
        ></n-input>
        <n-input
          v-model:value="jheerb.remark"
          type="text"
          placeholder="请输入备注"
          clearable
          class="mt20"
        ></n-input>
      </div>

      <div class="mt20 tr display-flex tr">
        <div>
          <n-button @click="fdgdfgdrb = false"> 取消 </n-button>
        </div>
        <div class="ml20">
          <n-button type="primary" @click="addZSdeb"> 确认 </n-button>
        </div>
      </div>
    </n-modal>

    <n-modal
      :mask-closable="false"
      v-model:show="ddsfdsrr"
      preset="card"
      class="Stock-diagnosis"
    >
      <template #header>
        <div>任务勘察详情</div>
      </template>
      <SurveyAndSteps
        :axId="axId"
        :seerert="seerert"
        @close="ddsfdsrr = false"
      ></SurveyAndSteps>
    </n-modal>

    <!-- <n-modal
      :mask-closable="false"
      v-model:show="showModalsweerr"
      preset="card"
      class="Stock-pdf"
    >
      <iframe
        frameborder="1"
        src="https://duxinggj-1251133427.cos.ap-guangzhou.myqcloud.com/dxgjAdmin/axedpdf/41654691524723.16%E9%80%BB%E8%BE%911%262-%E5%94%90%E5%86%B0%E8%80%81%E5%B8%88"
        ref="ifr"
        width="100%"
        height="560px"
        scrolling="auto"
      ></iframe>
    </n-modal> -->
  </div>
</template>
 <script lang='ts' setup>
import dxtable from "../../../components/util/dxtable.vue";
import SurveyAndSteps from "./components/SurveyAndSteps.vue";

import {
  dxget,
  transferTimeYMD,
  hf,
  dxpost,
  prefixS,
  qurl,
} from "../../../util/index";
import { useRouter, onBeforeRouteUpdate } from "vue-router";
import { NButton, NAlert, NStep, NSteps } from "naive-ui";
import {
  DeclareMeans,
  siteSoil,
  areas,
  statictype,
  Reviewtypes,
} from "../../../util/beRelieved/index";
import { h, ref, reactive } from "vue";
import { quyu } from "../../../util/beRelieved/quyu";
const Userid = localStorage.Userid;
const extra = ref({
  initiatorID: Userid,
  menderID: Userid,
});
const timestamp = ref();
const showModalsweerr = true;
const fdgdfgdra = ref(false);
const fdgdfgdrb = ref(false);
const ddsfdsrr = ref(false);
const axId = ref();
const seerert = ref();
const jheerr = ref({
  name: "",
  remark: "",
  type: 23,
});
const jheerb = ref({
  name: "",
  remark: "",
  type: 26,
});
const upload = {
  typeName: "pdf",
};
const appload = ref(false);
const daorujjeer = ref(false);
const dftte = ref(false);
const showModal = ref(false);
const showModaler = ref(false);
const showModalsan = ref(false);
const showModalsi = ref(false);
const isshowXz = ref(true);
const gval = ref();
const gvaler = ref();
const gvalercy = ref();
const remarksss = ref();
const goptions = ref();
const goptionser = ref();
const userInfosje = ref();
const getjbsdref = ref();
const dxtableRef = ref();
const gloading = ref(false);
const { currentRoute } = useRouter();
const checkedValue = ref("1");
const jhbeer = ref();
const SpData = ref();
const listArr = ref();
const cz = qurl();
let types = ref(0);
let urls = "?state=1";
const jnbnse = ref();
let zdy = [];
const hfe = (url) => {
  hf(url);
};
const czFun = {
  fun: (row) => {
    return [
      h(
        NButton,
        {
          type: "info",
          quaternary: true,
          onClick: async (e) => {
            jhbeer.value = row;
            await getjhee();
            showModalsi.value = true;
          },
        },
        "查看进度"
      ),
      h(
        NButton,
        {
          type: "info",
          quaternary: true,
          onClick: async (e) => {
            hf("particulars", { id: row.id });
          },
        },
        "详情"
      ),
    ];
  },
};

// if (currentRoute.value.name == "taskList") {
//   extra.value.initiatorID =
//   console.log(extra.value)

// }
// 任务分配
if (currentRoute.value.name == "TaskManager") {
  types.value = 1;
  isshowXz.value = false;
}
// 任务审核
if (currentRoute.value.name == "audit") {
  types.value = 2;
  isshowXz.value = false;
}

// 任务管理
if (currentRoute.value.name == "taskManagement") {
  types.value = 100;
  isshowXz.value = false;
}
// 任务取消
if (currentRoute.value.name == "cancel") {
  types.value = 101;
  isshowXz.value = false;
}
let headBtn = [
  {
    name: "任务发起 ",
    clickFun() {
      showModal.value = true;
      inistS();
    },
  },
];
if (types.value == 1) {
  urls = "?state=2,3";
  headBtn = [
    {
      name: "分配",
      clickFun() {
        showModaler.value = true;
        inistS();
      },
    },
  ];
}
if (types.value == 2) {
  urls = "?shenghe=2";
  headBtn = [
    {
      name: "审核",
      async clickFun() {
        const datase = dxtableRef.value.getpitchOn();
        const { data }: any = await dxget("beRelieved/Approval/getSpData", {
          ids: datase.join(","),
        });
        checkedValue.value = "1";
        showModalsan.value = true;
        jnbnse.value = data;
      },
    },
  ];
  zdy.push({
    title: "审核类型",
    key: "ReviewTypes",
    width: 80,
    render(row) {
      return Reviewtypes.filter((a) => a.value == row.ReviewTypes)[0].label;
    },
  });
  zdy.push({
    title: "取消原因",
    key: "reasonCancellation",
    ellipsis: {
      tooltip: true,
    },
    render(row) {
      let yx = "";
      try {
        const reasonCancellation = JSON.parse(row.reasonCancellation);
        yx = reasonCancellation.yx;
      } catch (e) {
        yx = "";
      }
      return yx;
    },
  });
}

let dataJson = reactive([
  {
    title: "任务ID",
    key: "id",
    width: 80,
  },
  {
    title: "申报时间",
    key: "TheTime",
    width: 90,
    search: true,
    type: "date",
    render(row) {
      return transferTimeYMD(row.TheTime);
    },
  },
  {
    title: "申报方式",
    width: 90,
    key: "DeclareMeans",
    search: true,
    type: "select",
    options: [
      {
        label: "全部",
        value: null,
      },
      ...DeclareMeans,
    ],
    render(row) {
      return getDeclareMeans(row.DeclareMeans);
    },
  },
  {
    title: "申报单位",
    key: "applicationUnit",
    search: true,
    width: 90,
    ellipsis: {
      tooltip: true,
    },
    type: "select",
    render(row) {
      return row.applicationUnit || "--";
    },
  },
  {
    title: "场地类型",
    width: 100,
    key: "typeOfSiteSoil",
    value: cz.typeOfSiteSoil,
    search: true,
    type: "select",
  },
  {
    title: "场地名称",
    search: true,
    width: 150,
    key: "SiteName",
    ellipsis: {
      tooltip: true,
    },
  },
  {
    title: "场地联系人",
    width: 90,
    search: true,
    key: "VenueContactPerson",
  },
  {
    title: "联系方式",
    width: 120,
    search: true,
    key: "contactway",
  },
  {
    title: "场地面积",
    width: 80,
    search: true,
    key: "PlaceArea",
    render(row) {
      return !row.PlaceArea ? "--" : row.PlaceArea + "m²";
    },
  },
  {
    title: "场地地址",
    key: "district",
    width: 200,
    ellipsis: {
      tooltip: true,
    },
    render(row) {
      return getdizhi(row.district, row.street, row.detailedAddress);
    },
  },

  {
    title: "管理组",
    width: 90,
    search: true,
    key: "ManagementGroup",
    type: "select",
    render(row) {
      let test = "";
      try {
        test = goptions.value.filter((a) => a.value == row.ManagementGroup)[0]
          .label;
      } catch (e) {}
      return test;
    },
  },

  {
    title: "勘察组",
    key: "Surveygroup",
    width: 80,
    search: true,
    type: "select",
    ellipsis: {
      tooltip: true,
    },
    render(row) {
      let test = "";
      try {
        test = goptionser.value.filter((a) => a.value == row.Surveygroup)[0]
          .label;
      } catch (e) {}
      return test || "--";
    },
  },
  {
    title: "勘察人",
    key: "SurveygroupRen",
    width: 80,
    ellipsis: {
      tooltip: true,
    },
    search: true,
    type: "select",
    render(row) {
      let test = "";
      try {
        test = userInfosje.value.filter((a) => a.id == row.SurveygroupRen)[0]
          .userNickname;
      } catch (e) {}
      return test || "--";
    },
  },
  {
    title: "安装组",
    key: "installationGroupId",
    search: true,
    type: "select",
    width: 80,
    ellipsis: {
      tooltip: true,
    },
    render(row) {
      let test = "";
      try {
        test = getjbsdref.value.filter(
          (a) => a.id == row.installationGroupId
        )[0].name;
      } catch (e) {}
      return test || "--";
    },
  },
  {
    title: "安装人",
    key: "installationGroupIdRen",
    width: 80,
    ellipsis: {
      tooltip: true,
    },
    search: true,
    type: "select",
    render(row) {
      let test = "";
      try {
        test = userInfosje.value.filter(
          (a) => a.id == row.installationGroupIdRen
        )[0].userNickname;
      } catch (e) {}
      return test || "--";
    },
  },
  {
    title: "状态",
    width: 80,
    key: "state",
    type: "select",
    search: false,
    search: true,
    type: "select",
    value: parseInt(cz.state) || "",
    render(row) {
      return getstatictype(row.state);
    },
  },
  {
    title: "备注",
    key: "remark",
    ellipsis: {
      tooltip: true,
    },
  },
  ...zdy,
]);
const jiedao = ref([]);
const jjnber = [
  {
    label: "深圳",
    value: null,
  },
  ...quyu,
];
const headerFrom = reactive([
  {
    title: "区",
    search: true,
    key: "district",
    type: "select",
    options: jjnber,
    value: cz.district,
    callBack(e) {
      dxtableRef.value.jiedaoNull();
      jiedao.value = [];
      if (!e) {
        return;
      }
      const jjnner = quyu.filter((b) => b.value == e)[0];
      jiedao.value = jjnner.xiaji;
    },
  },
  {
    title: "街道",
    search: true,
    key: "street",
    type: "select",
    options: jiedao,
  },
]);
if (types.value == 100) {
  urls = "";
  headBtn = [];
  dataJson[10].search = true;
}
if (types.value == 101) {
  urls = "?state=16";
  headBtn = [];
}

console.log(zdy);
const qx = {
  DeletePermissionID: "beRelieveddel", //删除
  EditPermissionIdentifier: "beRelievedbj", // 编辑
  NewPermissionIdentifier: "beRelievedxz", // 新建
  ViewPermissionID: "beRelievedck", // 查看
};

let portUrl = "beRelieved/axtask" + urls;
let formJson = ref([
  {
    title: "申报时间",
    type: "date",
    key: "TheTime",
    val: new Date().getTime(),
    required: true, // 是否为必填
  },
  {
    title: "申报方式",
    type: "select",
    key: "DeclareMeans",
    required: true, // 是否为必填
    val: 1,
    options: DeclareMeans,
    callBack(data) {
      let uuhe = false;
      if (data == 0) {
        uuhe = true;
      }
      formJson.value.filter((a) => a.key == "applicationUnit")[0].hide = uuhe;
    },
  },
  {
    title: "申报单位",
    key: "applicationUnit",

    required: true, // 是否为必填
    hide: false,
    type: "select",
  },
  {
    title: "场地类型",
    type: "select",
    key: "typeOfSiteSoil",
  },
  {
    title: "场地名称",
    type: "input",
    key: "SiteName",
    required: true, // 是否为必填
    search: true,
  },
  {
    title: "场地联系人",
    key: "VenueContactPerson",
    type: "input", //类型
    required: true, // 是否为必填
  },
  {
    title: "联系方式",
    key: "contactway",
    yzlx: "phone",
    type: "input", //类型
    required: true, // 是否为必填
  },
  {
    title: "场地面积",
    key: "PlaceArea",
    type: "input", //类型
    required: true, // 是否为必填
  },
  {
    title: "场地地址",
    key: "district,detailedAddress",
    type: "address", //类型
    required: true, // 是否为必填
  },
]);

const proxygroup = async (type) => {
  const { data }: any = await dxget("beRelieved/groupmanagement?type=" + type);
  const kjhber = [];
  data.map((a) => {
    kjhber.push({
      label: a.name,
      value: a.id,
    });
  });
  return kjhber;
};
const getUserInfo = async () => {
  const { data }: any = await dxget("beRelieved/getUserName");
  data.map((a) => {
    a.label = a.userNickname;
    a.value = a.id;
  });
  return data;
};
const getjbsdrserr = async () => {
  const { data }: any = await dxget("beRelieved/getUserName/getjbsd");
  return data;
};
const inistS = async () => {
  goptions.value = await proxygroup(23);
  dataJson[10].options = [{ label: "全部", value: "" }, ...goptions.value];
  goptionser.value = await proxygroup(26);
  dataJson[11].options = [{ label: "全部", value: "" }, ...goptionser.value];
  userInfosje.value = await getUserInfo();
  dataJson[12].options = [{ label: "全部", value: "" }, ...userInfosje.value];
  getjbsdref.value = await getjbsdrserr();

  const anzwe = await proxygroup(27);
  dataJson[13].options = [{ label: "全部", value: "" }, ...anzwe];
  dataJson[14].options = [{ label: "全部", value: "" }, ...userInfosje.value];
  dataJson[15].options = statictype;
};
inistS();
const getpitchOn = async (state, val?) => {
  gloading.value = true;
  const datase = dxtableRef.value.getpitchOn();
  const { code, data }: any = await dxget(
    "beRelieved/Bindingmanagementgroups",
    {
      ids: datase.join(","),
      state: state,
      TaskRrderId: gvalercy.value,
      val,
      remark: remarksss.value,
    }
  );
  gloading.value = false;
  showModal.value = false;
  showModaler.value = false;
  showModalsan.value = false;
  dxtableRef.value.initDataExpose();
};
// 路由变化触发
onBeforeRouteUpdate((a) => {
  dxtableRef.value.initDataExpose();
});
// 审核弹窗的单选框改变触发
const jnnjeea = (e) => {
  checkedValue.value = (e.target as HTMLInputElement).value;
};
// 审核弹窗确认按钮触发
const auditFun = async () => {
  const datase = dxtableRef.value.getpitchOn();
  const obj = {
    dy: 0,
    ids: datase.join(","),
  };
  if (checkedValue.value == "1") {
    obj.dy = 1;
  }
  // if (checkedValue.value == "2") {
  // }
  await dxpost("beRelieved/Approval", obj);
  dxtableRef.value.initDataExpose();
  showModalsan.value = false;
};
const getDeclareMeans = (data) => {
  try {
    return DeclareMeans.filter((a) => a.value == data)[0].label;
  } catch (e) {}
  return "--";
};
const getsiteSoil = (data) => {
  try {
    return siteSoil.filter((a) => a.value == data)[0].label;
  } catch (e) {}
  return "--";
};
const getstatictype = (data) => {
  try {
    return statictype.filter((a) => a.value == data)[0].label;
  } catch (e) {}
  return "--";
};
const getstatictypeer = (data, key) => {
  const jhbner = JSON.parse(data);
  return jhbner[key];
};
const getdizhi = (dt, st, detailedAddress) => {
  try {
    const district = quyu.filter((a) => a.value == dt)[0];
    const street = district.xiaji.filter((a) => a.value == st)[0].label;
    return district.label + street + detailedAddress;
  } catch (e) {}
  return "--";
};

const uploadxl = (data) => {
  readExcel(data.file.file);
};
// console.log(window.XLSX)
const readExcel = (file) => {
  // 解析Excel
  return new Promise(function () {
    // 返回Promise对象
    const reader = new FileReader();
    reader.onload = async (e) => {
      // 异步执行
      var data = e.target.result;
      let wb = window.XLSX.read(data, {
        type: "binary",
      });
      let worksheet = JSON.stringify(
        window.XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]])
      );
      console.log(worksheet);
      let worksheetarr = JSON.parse(worksheet);
      let kjhsd = [];
      const lijne = [];
      worksheetarr.map((a, b) => {
        const obj = {
          TheTime: "",
          DeclareMeans: "",
          applicationUnit: "",
          typeOfSiteSoil: "",
          SiteName: "",
          VenueContactPerson: "",
          contactway: "",
          district: "",
          street: "",
          detailedAddress: "",
          remark: "",
        };
        for (let key in a) {
          switch (key) {
            case "申报时间":
              let timer = "";
              try {
                if (a[key].indexOf("-") > 0) {
                  timer = a[key];
                } else {
                  timer = formatDate(a[key], "-");
                }
              } catch (e) {
                timer = formatDate(a[key], "-");
              }
              obj.TheTime = "" + new Date(timer).getTime();
              break;
            case "申报方式":
              let fdea = a[key];
              let code = 0;
              if (fdea == "官方申报") {
                code = 1;
              }
              obj.DeclareMeans = "" + code;
              break;

            case "申报单位":
              obj.applicationUnit = a[key];
              break;
            case "场地类型":
              obj.typeOfSiteSoil = a[key];
              break;
            case "场地名称":
              obj.SiteName = a[key];
              break;

            case "场地联系人":
              obj.VenueContactPerson = a[key];
              break;
            case "联系方式":
              obj.contactway = a[key];
              break;
            case "场地地址":
              try {
                const jhne = a[key];
                const district = jhne.split("区")[0] + "区";
                const street = jhne.split("道")[0].split("区")[1] + "道";
                obj.detailedAddress = jhne.split("道")[1];

                const shuye = quyu.filter((a) => a.label == district)[0];
                obj.district = shuye.value;
                const xkkds = shuye.xiaji.filter((a) => a.label == street)[0];
                obj.street = xkkds.value;
              } catch (e) {}
              break;
            case "备注":
              obj.remark = a[key];
              break;
          }
        }
        lijne.push(obj);
      });
      dftte.value = true;
      const { errno }: any = await dxpost("beRelieved/BatchAddingTasks", {
        list: JSON.stringify(lijne),
      });
      dftte.value = false;
      if (errno == 0) {
        window.$message.success("导入成功！");
        dxtableRef.value.initDataExpose();
        daorujjeer.value = false;
      } else {
        window.$message.error("导入失败！");
      }
    };
    reader.readAsBinaryString(file);
  });
};
const xiazai = () => {
  window.location.href =
    "https://duxinggj-1251133427.cos.ap-guangzhou.myqcloud.com/ax/%E4%BB%BB%E5%8A%A1%E5%AF%BC%E5%85%A5%E8%A1%A8%E6%A0%BC%E6%A8%A1%E6%9D%BF.xlsx";
};

const getCs = async () => {
  const { data }: any = await dxget("beRelieved/typeOfSiteSoil");
  const listArry = [
    {
      value: null,
      label: "全部",
    },
  ];
  data.map((a) => {
    listArry.push({
      value: a,
      label: a,
    });
  });
  dataJson[4].options = listArry;
  formJson.value[3].options = listArry;
};
getCs();
// dataJson[10].options = statictype;
const getCser = async () => {
  const { data }: any = await dxget("beRelieved/typeOfSiteSoil", { id: 23 });
  const listArry = [
    {
      value: null,
      label: "全部",
    },
  ];
  data.map((a) => {
    listArry.push({
      value: a,
      label: a,
    });
  });
  dataJson[3].options = listArry;
  formJson.value[2].options = listArry;
};
getCser();

const formatDate = (numb, format) => {
  let jisje = (numb - 1) * 24 * 3600000 + 1;
  const time = new Date(jisje);
  time.setFullYear(time.getFullYear() - 70);
  const year = time.getFullYear();
  let month = time.getMonth() + 1;
  let date = time.getDate() - 1;
  if (date == 0) {
    month = month - 1;
    if (
      month == 1 ||
      month == 3 ||
      month == 5 ||
      month == 7 ||
      month == 8 ||
      month == 10 ||
      month == 12
    ) {
      date = 31;
    } else if (month == 2) {
      date = 28;
    } else {
      date = 30;
    }
  }
  let strmonth = "",
    strdate = "";
  if (month < 10) {
    strmonth = "0" + month;
  } else {
    strmonth = "" + month;
  }
  if (date < 10) {
    strdate = "0" + date;
  } else {
    strdate = "" + date;
  }
  if (format && format.length === 1) {
    return year + format + strmonth + format + strdate;
  }
};

const addZSde = async () => {
  if (!jheerr.value.name) {
    window.$message.error("请输入组名称");
    return;
  }
  if (!jheerr.value.remark) {
    window.$message.error("请输入备注");
    return;
  }
  await dxpost("beRelieved/groupmanagement", jheerr.value);
  fdgdfgdra.value = false;
  inistS();
};
const addZSdeb = async () => {
  if (!jheerb.value.name) {
    window.$message.error("请输入组名称");
    return;
  }
  if (!jheerb.value.remark) {
    window.$message.error("请输入备注");
    return;
  }
  await dxpost("beRelieved/groupmanagement", jheerb.value);
  fdgdfgdrb.value = false;
  inistS();
};
const currentse = ref();
const getjhee = async (id?) => {
  const { data }: any = await dxget("beRelieved/steps", {
    taskId: id || jhbeer.value.id,
  });
  listArr.value = data.listArr;
  currentse.value = data.bz;
};

const getImgs = async (a) => {
  const responseText = JSON.parse(a.event.currentTarget.responseText);
  // formValue.value.appurl = responseText.data.imgurl;

  await dxpost("beRelieved/agreement", {
    id: jhbeer.value.id,
    xieyi: responseText.data.imgurl,
  });
  getjhee(jhbeer.value.id);
  appload.value = false;
};
const zuuhee = ref();
const jhnnerrr = ref();
const fjjnnerr = async (e) => {
  jhnnerrr.value = [];
  gvalercy.value = "";
  const { data }: any = await dxget(
    "dxgjAdmin/administrator?accountType=1&CharacterNameCode=" + e + "&page=1"
  );

  data.data.map((a) => {
    jhnnerrr.value.push({
      label: a.userNickname,
      value: a.id,
    });
  });
  console.log(data.data);
};

const daochukmse = async () => {
  const { data }: any = await dxget("beRelieved/public");
  const arrs = [];
  const arrst = [];
  dataJson.map((a) => {
    if (a.title != "操作") {
      arrst.push(a.title);
    }
  });

  arrs.push(arrst);

  data.map((a) => {
    const jjneer = [];
    dataJson.map((b) => {
      if (b.key == "TheTime") {
        jjneer.push(b.render(a));
      } else if (b.key == "DeclareMeans") {
        jjneer.push(b.render(a));
      } else if (b.key == "district") {
        jjneer.push(b.render(a));
      } else if (b.key == "ManagementGroup") {
        jjneer.push(b.render(a));
      } else if (b.key == "state") {
        jjneer.push(b.render(a));
      } else if (b.key == "Surveygroup") {
        jjneer.push(b.render(a));
      } else if (b.key == "SurveygroupRen") {
        jjneer.push(b.render(a));
      } else if (b.key == "installationGroupId") {
        jjneer.push(b.render(a));
      } else if (b.key == "installationGroupIdRen") {
        jjneer.push(b.render(a));
      } else if (b.key == "PlaceArea") {
        jjneer.push(b.render(a));
      } else {
        jjneer.push(a[b.key]);
      }
    });
    arrs.push(jjneer);
  });

  let jhhs = window.XLSX.utils.aoa_to_sheet(arrs);
  let workbook = window.XLSX.utils.book_new();
  console.log(jhhs);
  console.log(workbook);
  window.XLSX.utils.book_append_sheet(workbook, jhhs, "第一页");
  window.XLSX.writeFile(workbook, "任务列表.xlsx");
};

const showbiane = (id, str) => {
  axId.value = id;
  let jbser = "";

  switch (str) {
    case 1:
      jbser = "fdfa";
      break;
    case 2:
      jbser = "fdfb";
      break;
    case 3:
      jbser = "fdfc";
      break;
    case 4:
      jbser = "fdfd";
      break;
    case 5:
      jbser = "fdfe";
      break;
  }
  seerert.value = jbser;
  ddsfdsrr.value = true;
};

const quhgwe = async (id) => {
  if (!timestamp.value) {
    window.$message.error("请选择签署时间");
    return;
  }
  const { errno, data }: any = await dxpost(
    "beRelieved/phone/InvestigationList/xiugaisq",
    {
      id,
      SigningTime: timestamp.value,
    }
  );
  if (errno == 0) {
    window.$message.success(data);
  }
};
</script>
 <style scoped>
.renwu-label {
  width: 100px;
  text-align: right;
  margin-right: 20px;
}
.dsfdsfrtewe {
  margin-bottom: 20px;
}
.kknjseer {
  border-radius: 4px;
  border: 1px solid #e0e0e0;
  padding: 10px;
  margin-bottom: 10px;
}
.knnjswerrw {
  max-height: 500px;
  overflow: auto;
}
.kjnseert {
  width: 380px;
}
.dfsdrtr {
  display: inline-block;
}
</style>